#ifndef PROXYSTYLE_H
#define PROXYSTYLE_H
/*
 Source: http://labs.qt.nokia.com/2009/06/05/cross-platform-code-and-styles/
*/

#include <QWindowsStyle>
#include <QMotifStyle>
#include <QCleanlooksStyle>
#include <QPlastiqueStyle>
#include <QCDEStyle>
#include <QStyleFactory>
#include <QDialogButtonBox>

class ProxyStyle
{
public:
	ProxyStyle(const QString &baseStyle) { style = QStyleFactory::create(baseStyle); }
	int proxyStyleHint(QStyle::StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
	{
		if (hint == QStyle::SH_DialogButtonLayout) {
			return QDialogButtonBox::WinLayout;
		}
		return style->styleHint(hint, option, widget, returnData);
	}
private:
	QStyle *style;
};

#define ADDSTYLESUBCLASS(BaseStyleClass, BaseStyleName) \
class My##BaseStyleClass : public BaseStyleClass, public ProxyStyle \
{\
public:\
	My##BaseStyleClass() : BaseStyleClass(), ProxyStyle(BaseStyleName) {}\
	int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const\
	{\
		return proxyStyleHint(hint, option, widget, returnData);\
	}\
};

ADDSTYLESUBCLASS(QCleanlooksStyle, "cleanlooks");
ADDSTYLESUBCLASS(QPlastiqueStyle, "plastique");
ADDSTYLESUBCLASS(QMotifStyle, "motif");
ADDSTYLESUBCLASS(QWindowsStyle, "windows");
ADDSTYLESUBCLASS(QCDEStyle, "cde");
#ifdef Q_OS_WIN
#include <QWindowsXPStyle>
#include <QWindowsVistaStyle>
ADDSTYLESUBCLASS(QWindowsXPStyle, "windowsxp");
ADDSTYLESUBCLASS(QWindowsVistaStyle, "windowsvista");
#endif
#ifdef Q_OS_WINCE
#include <QWindowsCEStyle>
#include <QWindowsMobileStyle>
ADDSTYLESUBCLASS(QWindowsCEStyle, "windowsce");
ADDSTYLESUBCLASS(QWindowsMobileStyle, "windowsmobile");
#endif
#ifdef Q_OS_LINUX
#include <QGtkStyle>
ADDSTYLESUBCLASS(QGtkStyle, "gtk");
#endif
#ifdef Q_OS_MAC
#include <QMacStyle>
ADDSTYLESUBCLASS(QMacStyle, "macintosh");
#endif

QStyle *returnSubclassStyleForBaseStyle(QStyle *baseStyle)
{
	if (qobject_cast<QWindowsStyle *>(baseStyle)) {
		if (qobject_cast<QCleanlooksStyle *>(baseStyle)) {
#ifdef Q_OS_LINUX
			if (qobject_cast<QGtkStyle *>(baseStyle))
				return new MyQGtkStyle;
#endif
			return new MyQCleanlooksStyle;
		}
#ifdef Q_OS_MAC
		if (qobject_cast<QMacStyle *>(baseStyle))
			return new MyQMacStyle;
#endif
		if (qobject_cast<QPlastiqueStyle *>(baseStyle))
			return new MyQPlastiqueStyle;
#ifdef Q_OS_WIN
		if (qobject_cast<QWindowsXPStyle *>(baseStyle)) {
			if (qobject_cast<QWindowsVistaStyle *>(baseStyle))
				return new MyQWindowsVistaStyle;
			return new MyQWindowsXPStyle;
		}
#endif
#ifdef Q_OS_WINCE
		if (qobject_cast<QWindowsCEStyle *>(baseStyle))
			return new MyQWindowsCEStyle;
		if (qobject_cast<QWindowsMobileStyle *>(baseStyle))
			return new MyQWindowsMobileStyle;
#endif
		return new MyQWindowsStyle;
	}
	if (qobject_cast<QMotifStyle *>(baseStyle)) {
		if (qobject_cast<QCDEStyle *>(baseStyle))
			return new MyQCDEStyle;
		return new MyQMotifStyle;
	}
	return baseStyle;
}

#endif
